﻿using Common;
using DevExpress.XtraEditors;
using DLL;
using NursingFormSystem;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using NursingFormSystem.NurFormsService;
using NursingFormSystem.Transfusion;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace ShiftProject.Transfusion
{
    public partial class RecordsSafeCare : Form
    {
        //窗体构造函数
        public NursingForm formService = new NursingForm();
        NursingFormRecord record = new NursingFormRecord();
        PatientInfo PatientInfo;
        Tb_User LoginUser;
        ElectronicSignature es;
        string Id;
        public RecordsSafeCare(Tb_User loginUser, PatientInfo patientInfo)
        {
            //绑定控件
            InitializeComponent();
            //成员变量赋值
            this.LoginUser = loginUser;
            this.PatientInfo = patientInfo;
            es = new ElectronicSignature(LoginUser);//电签实例化
            //绑定数据
            BindInfo(this.Id);
        }
        public RecordsSafeCare(string[] loginUser, string[] patientInfo)
        {
            //绑定控件
            InitializeComponent();
            //成员变量赋值
            this.LoginUser = ArrayToObject.ArrayToLoginUser(loginUser);
            this.PatientInfo = ArrayToObject.ArrayToPatientInfo(patientInfo);
            es = new ElectronicSignature(LoginUser);//电签实例化
            //绑定数据
            BindInfo(this.Id);
        }

        //血型种类-其他文本框，默认隐藏，勾选'其他'，文本框出现并可填写
        private void QIta_SelectedValueChanged(object sender, EventArgs e)
        {
            textxyzlqita.Visible = false;
            if (checkEditqita.Checked)
            {
                textxyzlqita.Visible = true;
            }
            else { textxyzlqita.Text = string.Empty; }
        }

        private void RecordsSafeCare_Load(object sender, EventArgs e)
        {
            BindInfo(this.Id);
        }

        private void BindInfo(string id)
        {
            dateEditriqi.DateTime = DateTime.Now;
            timeshijian.EditValue = null;
            timeshijian1.EditValue = null;
            timeShiJian2.EditValue = null;
            timeShiJian3.EditValue = null;
            timeShiJian4.EditValue = null;
            timeShiJian5.EditValue = null;
            radioGroupbrjbxx.SelectedIndex = -1;
            radioGroupxuexing.SelectedIndex = -1;
            radioGroup2RH.SelectedIndex = -1;
            radioGroupxuedaiwaiguan.SelectedIndex = -1;
            radioGroupjcnjfy.SelectedIndex = -1;
            radioGroupxuedaitiaoxingma.SelectedIndex = -1;
            radioGroupBuLiangFanYing2.SelectedIndex = -1;
            radioGroupBuLiangFanYing3.SelectedIndex = -1;
            radioGroupBuLiangFanYing4.SelectedIndex = -1;
            radioGroupBuLiangFanYing5.SelectedIndex = -1;
            radioGroupxdbc.SelectedIndex = -1;
            radioGroupRH.SelectedIndex = -1;
            radioGrouphzxx.SelectedIndex = -1;
            textsudu.EditValue = "    /";
            textSuDu5.EditValue = "    /";
            textBuLiangFanYing.EditValue = "    /";
            textBuLiangFanYing1.EditValue = "    /";
            //住院号
            record.PatientId = PatientInfo.PATIENT_ID;
            //住院次数
            record.VisitId = PatientInfo.VISIT_ID;
            //患者姓名
            record.PatientName = PatientInfo.PATIENT_NAME;
            //床号
            record.BedNo = PatientInfo.BED_NO;
            //当前患者科室ID
            record.DepartmentId = PatientInfo.DEPARTMENT_ID;
            //当前患者科室名称
            record.DepartmentName = PatientInfo.DEPARTMENT_NAME;
            //当前患者病区ID
            record.AreaId = PatientInfo.NURSE_CELL_CODE;
            //当前患者病区名称
            record.AreaName = PatientInfo.NURSE_CELL_NAME;

            var ret = formService.GetNursingFormRecordOrderByTime(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID, (int)FormType.Transfuse, 1);
            if (ret.Code == 1)
            {
                List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
                if (string.IsNullOrEmpty(this.Id))
                    record = list[0];
                else
                    record = list.Find(p => p.Id == Convert.ToInt32(this.Id));
                this.Id = record.Id.ToString();
                var NursingFormData = record.NursingFormData;
                Transfuse tf = new Transfuse();
                tf = XmlUtil.XMLToObject<Transfuse>(NursingFormData, Encoding.UTF8);
                //患者血型
                radioGrouphzxx.SelectedIndex = Convert.ToInt32(tf.XueXing == "" ? "-1" : tf.XueXing);
                //RH
                radioGroupRH.SelectedIndex = Convert.ToInt32(tf.RH == "" ? "-1" : tf.RH);
                //输血日期
                dateEditriqi.Text = tf.ShuXueRiQi;
                //病人基本信息
                radioGroupbrjbxx.SelectedIndex = Convert.ToInt32(tf.HeDuiNeiRong.BingRenJiBenXinXi == "" ? "-1" : tf.HeDuiNeiRong.BingRenJiBenXinXi);
                //血型
                radioGroupxuexing.SelectedIndex = Convert.ToInt32(tf.HeDuiNeiRong.XueXing == "" ? "-1" : tf.HeDuiNeiRong.XueXing);
                //RH
                radioGroup2RH.SelectedIndex = Convert.ToInt32(tf.HeDuiNeiRong.RH == "" ? "-1" : tf.HeDuiNeiRong.RH);
                //血液种类
                var quanxue = tf.HeDuiNeiRong.XueYeZhongLei.Split('#');
                checkEditquanxue.Checked = (quanxue[0] == "1");
                checkEditxuanfuhongxibao.Checked = (quanxue[1] == "1");
                checkEditxidihongxibao.Checked = (quanxue[2] == "1");
                checkEditxuexiaoban.Checked = (quanxue[3] == "1");
                checkEditxinxianbingdongxuejiang.Checked = (quanxue[4] == "1");
                checkEditbingdongxuejiang.Checked = (quanxue[5] == "1");
                checkEditlengchendian.Checked = (quanxue[6] == "1");
                checkEditqita.Checked = (quanxue[7] == "1");
                textxyzlqita.Text = tf.HeDuiNeiRong.XYZL_QiTa;  //  血液种类--其他-文本框的值
                //血液数量
                textEdit1xysl.Text = tf.HeDuiNeiRong.XueYeShuLiang;
                textEdit2xysl.Text = tf.HeDuiNeiRong.XueYeShuLiangml;
                //交叉配血凝集反应
                //radioGroupjcnjfy.SelectedIndex = Convert.ToInt32(tf.HeDuiNeiRong.NingJiFanYing == "" ? "-1" : (tf.HeDuiNeiRong.NingJiFanYing == "0" ? 1 : 0));
                string njfy = tf.HeDuiNeiRong.NingJiFanYing;
                radioGroupjcnjfy.SelectedIndex = -1;
                if (!string.IsNullOrEmpty(njfy))
                {
                    radioGroupjcnjfy.SelectedIndex = njfy == "0" ? 1 : 0;//index:1是无，index:0是有
                }
                //血袋外观
                radioGroupxuedaiwaiguan.SelectedIndex = Convert.ToInt32(tf.HeDuiNeiRong.XueDaiWaiGuan == "" ? "-1" : tf.HeDuiNeiRong.XueDaiWaiGuan);
                //血袋条形码
                radioGroupxuedaitiaoxingma.SelectedIndex = Convert.ToInt32(tf.HeDuiNeiRong.XueDaiTiaoXingMa == "" ? "-1" : tf.HeDuiNeiRong.XueDaiTiaoXingMa);
                //输血前核对签名--初核者
                textsxqhdqmchz.Text = tf.HeDuiNeiRong.SXQHDQM_ChuHeZhe;
                //输血前核对签名--初核者-电签
                es.SetSiginPic(LoginUser.DepartmentCode, tf.HeDuiNeiRong.SXQHDQM_ChuHeZhe_ID, picElectronicSignature1, textsxqhdqmchz.Location, textsxqhdqmchz);
                if (textsxqhdqmchz.Text.Equals(this.LoginUser.UserName)) textsxqhdqmchzId = true;
                //输血前核对签名--复核者
                textsxqhdqmfhz.Text = tf.HeDuiNeiRong.SXQHDQM_FuHeZhe;
                //输血前核对签名--复核者-电签
                es.SetSiginPic(LoginUser.DepartmentCode, tf.HeDuiNeiRong.SXQHDQM_FuHeZhe_ID, picElectronicSignature2, textsxqhdqmfhz.Location, textsxqhdqmfhz);
                if (textsxqhdqmfhz.Text.Equals(this.LoginUser.UserName)) textsxqhdqmfhzId = true;
                //床旁核对签名--初核者
                textcphdqmchz.Text = tf.HeDuiNeiRong.CPHDQM_ChuHeZhe;
                //床旁核对签名--初核者-电签
                es.SetSiginPic(LoginUser.DepartmentCode, tf.HeDuiNeiRong.CPHDQM_ChuHeZhe_ID, picElectronicSignature3, textcphdqmchz.Location, textcphdqmchz);
                if (textcphdqmchz.Text.Equals(this.LoginUser.UserName)) textcphdqmchzId = true;
                //床旁核对签名--初核者
                textcphdqmfhz.Text = tf.HeDuiNeiRong.CPHDQM_FuHeZhe;
                //床旁核对签名--初核者-电签
                es.SetSiginPic(LoginUser.DepartmentCode, tf.HeDuiNeiRong.CPHDQM_FuHeZhe_ID, picElectronicSignature4, textcphdqmfhz.Location, textcphdqmfhz);
                if (textcphdqmfhz.Text.Equals(this.LoginUser.UserName)) textcphdqmfhzId = true;
                //监测内容--输血前
                if (!string.IsNullOrEmpty(tf.JianCeNeiRongList[0].ShiJian))
                {
                    timeshijian.Text = DateTimeHelper.HHmmssToHHmm(tf.JianCeNeiRongList[0].ShiJian);
                }
                comboBoxEditshenzhi.Text = tf.JianCeNeiRongList[0].ShenZhi;  //  神志
                texttiwen.Text = tf.JianCeNeiRongList[0].TiWen;  //  体温
                textMaiBo.Text = tf.JianCeNeiRongList[0].MaiBo;  //脉搏
                textHuXi.Text = tf.JianCeNeiRongList[0].HuXi;  //呼吸
                textXueYa.Text = tf.JianCeNeiRongList[0].XueYa;   //血压
                textsudu.Text = tf.JianCeNeiRongList[0].SuDu;   //速度
                textBuLiangFanYing.Text = tf.JianCeNeiRongList[0].BuLiangFanYing;  //不良反应
                textHuShiQianMing.Text = tf.JianCeNeiRongList[0].HuShiQianMing;   //护士签名
                //监测内容--输血开始时
                if (!string.IsNullOrEmpty(tf.JianCeNeiRongList[1].ShiJian))
                {
                    timeshijian1.Text = DateTimeHelper.HHmmssToHHmm(tf.JianCeNeiRongList[1].ShiJian);
                }
                comboBoxshenzhi1.Text = tf.JianCeNeiRongList[1].ShenZhi;
                texttiwen1.Text = tf.JianCeNeiRongList[1].TiWen;
                textMaiBo1.Text = tf.JianCeNeiRongList[1].MaiBo;
                textHuXi1.Text = tf.JianCeNeiRongList[1].HuXi;
                textXueYa1.Text = tf.JianCeNeiRongList[1].XueYa;
                textSuDu1.Text = tf.JianCeNeiRongList[1].SuDu;
                textBuLiangFanYing1.Text = tf.JianCeNeiRongList[1].BuLiangFanYing;
                textHuShiQianMing1.Text = tf.JianCeNeiRongList[1].HuShiQianMing;
                //监测内容--输血开始后15min
                if (!string.IsNullOrEmpty(tf.JianCeNeiRongList[2].ShiJian))
                {
                    timeShiJian2.Text = DateTimeHelper.HHmmssToHHmm(tf.JianCeNeiRongList[2].ShiJian);
                }
                comboBoxShenZhi2.Text = tf.JianCeNeiRongList[2].ShenZhi;
                textTiWen2.Text = tf.JianCeNeiRongList[2].TiWen;
                textMaiBo2.Text = tf.JianCeNeiRongList[2].MaiBo;
                textHuXi2.Text = tf.JianCeNeiRongList[2].HuXi;
                textXueYa2.Text = tf.JianCeNeiRongList[2].XueYa;
                textSuDu2.Text = tf.JianCeNeiRongList[2].SuDu;
                radioGroupBuLiangFanYing2.SelectedIndex = -1;
                string blfy2 = tf.JianCeNeiRongList[2].BuLiangFanYing;
                if (!string.IsNullOrEmpty(blfy2))
                {
                    radioGroupBuLiangFanYing2.SelectedIndex = blfy2 == "0" ? 1 : 0;
                }
                textHuShiQianMing2.Text = tf.JianCeNeiRongList[2].HuShiQianMing;
                //监测内容--输血期间1
                if (!string.IsNullOrEmpty(tf.JianCeNeiRongList[3].ShiJian))
                {
                    timeShiJian3.Text = DateTimeHelper.HHmmssToHHmm(tf.JianCeNeiRongList[3].ShiJian);
                }
                comboBoxShenZhi3.Text = tf.JianCeNeiRongList[3].ShenZhi;
                textTiWen3.Text = tf.JianCeNeiRongList[3].TiWen;
                textMaiBo3.Text = tf.JianCeNeiRongList[3].MaiBo;
                textHuXi3.Text = tf.JianCeNeiRongList[3].HuXi;
                textXueYa3.Text = tf.JianCeNeiRongList[3].XueYa;
                textSuDu3.Text = tf.JianCeNeiRongList[3].SuDu;
                radioGroupBuLiangFanYing3.SelectedIndex = -1;
                string blfy3 = tf.JianCeNeiRongList[3].BuLiangFanYing;
                if (!string.IsNullOrEmpty(blfy3))
                {
                    radioGroupBuLiangFanYing3.SelectedIndex = blfy3 == "0" ? 1 : 0;
                }
                textHuShiQianMing3.Text = tf.JianCeNeiRongList[3].HuShiQianMing;
                //监测内容--输血期间2
                if (!string.IsNullOrEmpty(tf.JianCeNeiRongList[4].ShiJian))
                {
                    timeShiJian4.Text = DateTimeHelper.HHmmssToHHmm(tf.JianCeNeiRongList[4].ShiJian);
                }
                comboBoxShenZhi4.Text = tf.JianCeNeiRongList[4].ShenZhi;
                textTiWen4.Text = tf.JianCeNeiRongList[4].TiWen;
                textMaiBo4.Text = tf.JianCeNeiRongList[4].MaiBo;
                textHuXi4.Text = tf.JianCeNeiRongList[4].HuXi;
                textXueYa4.Text = tf.JianCeNeiRongList[4].XueYa;
                textSuDu4.Text = tf.JianCeNeiRongList[4].SuDu;
                //radioGroupBuLiangFanYing4.SelectedIndex = Convert.ToInt32(tf.JianCeNeiRongList[4].BuLiangFanYing == "" ? "-1" : tf.JianCeNeiRongList[4].BuLiangFanYing);
                radioGroupBuLiangFanYing4.SelectedIndex = -1;
                string blfy4 = tf.JianCeNeiRongList[4].BuLiangFanYing;
                if (!string.IsNullOrEmpty(blfy4))
                {
                    radioGroupBuLiangFanYing4.SelectedIndex = blfy4 == "0" ? 1 : 0;
                }
                textHuShiQianMing4.Text = tf.JianCeNeiRongList[4].HuShiQianMing;
                //监测内容--输血完成时
                if (!string.IsNullOrEmpty(tf.JianCeNeiRongList[5].ShiJian))
                {
                    timeShiJian5.Text = DateTimeHelper.HHmmssToHHmm(tf.JianCeNeiRongList[5].ShiJian);
                }
                comboBoxShenZhi5.Text = tf.JianCeNeiRongList[5].ShenZhi;
                textTiWen5.Text = tf.JianCeNeiRongList[5].TiWen;
                textMaiBo5.Text = tf.JianCeNeiRongList[5].MaiBo;
                textHuXi5.Text = tf.JianCeNeiRongList[5].HuXi;
                textXueYa5.Text = tf.JianCeNeiRongList[5].XueYa;
                textSuDu5.Text = tf.JianCeNeiRongList[5].SuDu;
                //radioGroupBuLiangFanYing5.SelectedIndex = Convert.ToInt32(tf.JianCeNeiRongList[5].BuLiangFanYing == "" ? "-1" : tf.JianCeNeiRongList[5].BuLiangFanYing);
                radioGroupBuLiangFanYing5.SelectedIndex = -1;
                string blfy5 = tf.JianCeNeiRongList[5].BuLiangFanYing;
                if (!string.IsNullOrEmpty(blfy5))
                {
                    radioGroupBuLiangFanYing5.SelectedIndex = blfy5 == "0" ? 1 : 0;
                }
                textHuShiQianMing5.Text = tf.JianCeNeiRongList[5].HuShiQianMing;
                //不良反应情况
                memoEditbuliangfanyin.Text = tf.BuLiangFanYingQingKuang.BLFYQK_NeiRong;
                //输血完将用过的血袋按规定保存24小时
                radioGroupxdbc.SelectedIndex = Convert.ToInt32(tf.BuLiangFanYingQingKuang.XueDaiBaoCun == "" ? "-1" : tf.BuLiangFanYingQingKuang.XueDaiBaoCun);
                record.NursingFormData = XmlUtil.ObjectToXML(tf, Encoding.UTF8);
            }
            else if (ret.Code == 2)
            {
                InsertMode(false);
                return;
            }
            else
            {
                MessageBox.Show(ret.M);
            }
        }

        //保存
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(dateEditriqi.Text))
                dateEditriqi.DateTime = DateTime.Now;
            Transfuse tf = new Transfuse();
            string buttonText = ((DevExpress.XtraEditors.SimpleButton)(sender)).Text;
            //核对内容
            tf.HeDuiNeiRong.BingRenJiBenXinXi = radioGroupbrjbxx.EditValue + "";  //病人基本信息
            tf.HeDuiNeiRong.XueXing = radioGroupxuexing.EditValue + "";  //血型
            tf.HeDuiNeiRong.RH = radioGroup2RH.EditValue + "";  //RH
            tf.HeDuiNeiRong.XueYeZhongLei = (checkEditquanxue.Checked ? "1" : "0") + "#" + (checkEditxuanfuhongxibao.Checked ? "1" : "0") + "#" +
                                            (checkEditxidihongxibao.Checked ? "1" : "0") + "#" + (checkEditxuexiaoban.Checked ? "1" : "0") + "#" +
                                            (checkEditxinxianbingdongxuejiang.Checked ? "1" : "0") + "#" + (checkEditbingdongxuejiang.Checked ? "1" : "0") + "#" +
                                            (checkEditlengchendian.Checked ? "1" : "0") + "#" + (checkEditqita.Checked ? "1" : "0");    //  血液种类
            tf.HeDuiNeiRong.XYZL_QiTa = textxyzlqita.Text;  //  血液种类--其他
            tf.HeDuiNeiRong.XueYeShuLiang = textEdit1xysl.Text;  //  血液数量μ
            tf.HeDuiNeiRong.XueYeShuLiangml = textEdit2xysl.Text;  //  血液数量ml
            tf.HeDuiNeiRong.NingJiFanYing = radioGroupjcnjfy.EditValue + "";  // 交叉配血凝集反应
            tf.HeDuiNeiRong.XueDaiWaiGuan = radioGroupxuedaiwaiguan.EditValue + "";  //  血袋外观
            tf.HeDuiNeiRong.XueDaiTiaoXingMa = radioGroupxuedaitiaoxingma.EditValue + "";  // 血袋条形码

            tf.HeDuiNeiRong.SXQHDQM_ChuHeZhe = textsxqhdqmchz.Text;  //  输血前核对签名--初核者
            if (textsxqhdqmchzId && !string.IsNullOrEmpty(textsxqhdqmchz.Text) && textsxqhdqmchz.Text.Equals(this.LoginUser.UserName))
                tf.HeDuiNeiRong.SXQHDQM_ChuHeZhe_ID = this.LoginUser.UserId;

            tf.HeDuiNeiRong.SXQHDQM_FuHeZhe = textsxqhdqmfhz.Text;  //   输血前核对签名--复核者
            if (textsxqhdqmfhzId && !string.IsNullOrEmpty(textsxqhdqmfhz.Text) && textsxqhdqmfhz.Text.Equals(this.LoginUser.UserName))
                tf.HeDuiNeiRong.SXQHDQM_FuHeZhe_ID = this.LoginUser.UserId;

            tf.HeDuiNeiRong.CPHDQM_ChuHeZhe = textcphdqmchz.Text;  //    床旁核对签名--初核者
            if (textcphdqmchzId && !string.IsNullOrEmpty(textcphdqmchz.Text) && textcphdqmchz.Text.Equals(this.LoginUser.UserName))
                tf.HeDuiNeiRong.CPHDQM_ChuHeZhe_ID = this.LoginUser.UserId;

            tf.HeDuiNeiRong.CPHDQM_FuHeZhe = textcphdqmfhz.Text;  //    床旁核对签名--复核者
            if (textcphdqmfhzId && !string.IsNullOrEmpty(textcphdqmfhz.Text) && textcphdqmfhz.Text.Equals(this.LoginUser.UserName))
                tf.HeDuiNeiRong.CPHDQM_FuHeZhe_ID = this.LoginUser.UserId;

            for (int i = 0; i < 6; i++)
            {
                JianCeNeiRong jc = new JianCeNeiRong();
                if (i == 0)
                {
                    //监测内容--输血前
                    jc.ShiJian = DateTimeHelper.HHmmssToHHmm(timeshijian.Text);  //时间
                    jc.ShenZhi = comboBoxEditshenzhi.Text;  //  神志
                    jc.TiWen = texttiwen.Text;  //  体温
                    jc.MaiBo = textMaiBo.Text;  //脉搏
                    jc.HuXi = textHuXi.Text;  //呼吸
                    jc.XueYa = textXueYa.Text;   //血压
                    jc.SuDu = textsudu.Text;   //速度
                    jc.BuLiangFanYing = textBuLiangFanYing.Text;  //不良反应
                    jc.HuShiQianMing = textHuShiQianMing.Text;   //护士签名
                }
                else if (i == 1)
                {
                    //监测内容--输血开始时
                    jc.ShiJian = DateTimeHelper.HHmmssToHHmm(timeshijian1.Text);
                    //jc.ShiJian = timeshijian1.Text;
                    jc.ShenZhi = comboBoxshenzhi1.Text;
                    jc.TiWen = texttiwen1.Text;
                    jc.MaiBo = textMaiBo1.Text;
                    jc.HuXi = textHuXi1.Text;
                    jc.XueYa = textXueYa1.Text;
                    jc.SuDu = textSuDu1.Text;
                    jc.BuLiangFanYing = textBuLiangFanYing1.Text;
                    jc.HuShiQianMing = textHuShiQianMing1.Text;
                }
                else if (i == 2)
                {
                    //监测内容--输血开始后15min
                    jc.ShiJian = DateTimeHelper.HHmmssToHHmm(timeShiJian2.Text);
                    jc.ShenZhi = comboBoxShenZhi2.Text;
                    jc.TiWen = textTiWen2.Text;
                    jc.MaiBo = textMaiBo2.Text;
                    jc.HuXi = textHuXi2.Text;
                    jc.XueYa = textXueYa2.Text;
                    jc.SuDu = textSuDu2.Text;
                    jc.BuLiangFanYing = radioGroupBuLiangFanYing2.EditValue + "";
                    jc.HuShiQianMing = textHuShiQianMing2.Text;
                }
                else if (i == 3)
                {
                    //监测内容--输血期间1
                    jc.ShiJian = DateTimeHelper.HHmmssToHHmm(timeShiJian3.Text);
                    jc.ShenZhi = comboBoxShenZhi3.Text;
                    jc.TiWen = textTiWen3.Text;
                    jc.MaiBo = textMaiBo3.Text;
                    jc.HuXi = textHuXi3.Text;
                    jc.XueYa = textXueYa3.Text;
                    jc.SuDu = textSuDu3.Text;
                    jc.BuLiangFanYing = radioGroupBuLiangFanYing3.EditValue + "";
                    jc.HuShiQianMing = textHuShiQianMing3.Text;
                }
                else if (i == 4)
                {
                    //监测内容--输血期间2
                    jc.ShiJian = DateTimeHelper.HHmmssToHHmm(timeShiJian4.Text);
                    jc.ShenZhi = comboBoxShenZhi4.Text;
                    jc.TiWen = textTiWen4.Text;
                    jc.MaiBo = textMaiBo4.Text;
                    jc.HuXi = textHuXi4.Text;
                    jc.XueYa = textXueYa4.Text;
                    jc.SuDu = textSuDu4.Text;
                    jc.BuLiangFanYing = radioGroupBuLiangFanYing4.EditValue + "";
                    jc.HuShiQianMing = textHuShiQianMing4.Text;
                }
                else if (i == 5)
                {
                    //监测内容--输血完成时
                    jc.ShiJian = DateTimeHelper.HHmmssToHHmm(timeShiJian5.Text);
                    jc.ShenZhi = comboBoxShenZhi5.Text;
                    jc.TiWen = textTiWen5.Text;
                    jc.MaiBo = textMaiBo5.Text;
                    jc.HuXi = textHuXi5.Text;
                    jc.XueYa = textXueYa5.Text;
                    jc.SuDu = textSuDu5.Text;
                    jc.BuLiangFanYing = radioGroupBuLiangFanYing5.EditValue + "";
                    jc.HuShiQianMing = textHuShiQianMing5.Text;
                }
                tf.JianCeNeiRongList.Add(jc);
            }

            //不良反应情况
            tf.BuLiangFanYingQingKuang.BLFYQK_NeiRong = memoEditbuliangfanyin.Text;
            tf.BuLiangFanYingQingKuang.XueDaiBaoCun = radioGroupxdbc.EditValue + "";   //  输血完将用过的血袋按规定保存24小时
            tf.XueXing = radioGrouphzxx.EditValue + "";    //患者血型
            tf.RH = radioGroupRH.EditValue + "";          //RH
            tf.ShuXueRiQi = dateEditriqi.DateTime.ToString("yyyy-MM-dd HH:mm:ss");    //输血日期
            tf.FormId = (int)FormType.Transfuse;
            tf.FormName = EnumHelper.GetDescription(FormType.Transfuse);
            record.NursingFormData = XmlUtil.ObjectToXML(tf, Encoding.UTF8);
            //表单ID
            record.FormId = (int)FormType.Transfuse;
            record.FormName = EnumHelper.GetDescription(FormType.Transfuse);
            //住院号
            record.PatientId = PatientInfo.PATIENT_ID;
            //住院次数
            record.VisitId = PatientInfo.VISIT_ID;
            //患者姓名
            record.PatientName = PatientInfo.PATIENT_NAME;
            //床号
            record.BedNo = PatientInfo.BED_NO;
            //当前患者科室ID
            record.DepartmentId = PatientInfo.DEPARTMENT_ID;
            //当前患者科室名称
            record.DepartmentName = PatientInfo.DEPARTMENT_NAME;
            //当前患者病区ID
            record.AreaId = PatientInfo.NURSE_CELL_CODE;
            //当前患者病区名称
            record.AreaName = PatientInfo.NURSE_CELL_NAME;
            record.AssessmentDate = dateEditriqi.DateTime;
            record.Id = Id == "" ? 0 : Convert.ToInt32(Id);
            var ret = formService.SetNursingFormRecord(Newtonsoft.Json.JsonConvert.SerializeObject(record));

            if (ret.Code == 1)
            {
                MessageBox.Show(record.Id == 0 ? "新增成功" : "更新成功");
                if (record.Id > 0) return;
                //新增成功后绑定数据
                this.Id = string.Empty;
                BindInfo(this.Id);
            }
            else
            {
                MessageBox.Show(ret.M);
            }
            //点击保存完后，关闭新增页面
            this.DialogResult = DialogResult.OK;
        }

        /// <summary>
        /// 历史按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHis_Click(object sender, EventArgs e)
        {
            HistoryTF f = new HistoryTF(PatientInfo);
            f.ShowDialog();
            if (f.DialogResult != DialogResult.OK) return;
            if (string.IsNullOrEmpty(f.Id)) return;
            this.Id = f.Id;
            BindInfo(this.Id);
        }

        private void timeshijian_DoubleClick(object sender, EventArgs e)
        {
            this.timeshijian.Text = DateTime.Now.ToString("HH:mm");
        }

        private void timeshijian1_DoubleClick(object sender, EventArgs e)
        {
            timeshijian1.Text = DateTime.Now.ToString("HH:mm");
        }

        private void timeShiJian2_DoubleClick(object sender, EventArgs e)
        {
            timeShiJian2.Text = DateTime.Now.ToString("HH:mm");
        }

        private void timeShiJian3_DoubleClick(object sender, EventArgs e)
        {
            timeShiJian3.Text = DateTime.Now.ToString("HH:mm");
        }

        private void timeShiJian4_DoubleClick(object sender, EventArgs e)
        {
            timeShiJian4.Text = DateTime.Now.ToString("HH:mm");
        }

        private void timeShiJian5_DoubleClick(object sender, EventArgs e)
        {
            timeShiJian5.Text = DateTime.Now.ToString("HH:mm");
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Id)) { MessageBox.Show("当前为新增模式，无法操作"); return; }
            BindInfo(this.Id);
        }
        /// <summary>
        /// 打印事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Id)) { MessageBox.Show("当前为新增模式，无法操作"); return; }
            RecordsSafePrints f = new RecordsSafePrints(LoginUser, PatientInfo, string.Empty);
            f.Show();
        }
        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Id)) { MessageBox.Show("当前为新增模式，无法操作"); return; }
            if (MessageBox.Show("确定要删除数据吗？", "删除前确认", MessageBoxButtons.OKCancel) != DialogResult.OK) return;

            var ret = formService.DeleteNursingFormRecord(this.Id);
            MessageBox.Show(ret.M);
            if (ret.Code != 1) return;

            this.Id = string.Empty;
            BindInfo(this.Id);

        }
        /// <summary>
        /// 没有记录单的时候
        /// </summary>
        private void ShowClose()
        {
            MessageBox.Show(string.Format("该患者没有《{0}》 \r\n 自动转入新增界面", EnumHelper.GetDescription(FormType.Transfuse)),
                            "关闭提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            InsertMode(false);
        }
        /// <summary>
        /// 新增按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNew_Click(object sender, EventArgs e)
        {
            InsertMode(true);
        }
        /// <summary>
        /// 进入新增模式
        /// </summary>
        /// <param name="openTips">是否需要来个提醒</param>
        private void InsertMode(bool openTips)
        {
            if (openTips && MessageBox.Show("是否新增该表单", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
                return;
            foreach (Control c in panel1.Controls)
                ControlValueClear(c);
            foreach (Control c in groupControl1.Controls)
                ControlValueClear(c);
            foreach (Control c in groupControl2.Controls)
                ControlValueClear(c);
            foreach (Control c in groupControl3.Controls)
                ControlValueClear(c);
            foreach (Control c in panel2.Controls)
                ControlValueClear(c);

            textsxqhdqmchz.Visible = true;
            textsxqhdqmfhz.Visible = true;
            textcphdqmchz.Visible = true;
            textcphdqmfhz.Visible = true;
            picElectronicSignature1.Visible = false;
            picElectronicSignature2.Visible = false;
            picElectronicSignature3.Visible = false;
            picElectronicSignature4.Visible = false;
            textsxqhdqmchzId = false;
            textsxqhdqmfhzId = false;
            textcphdqmchzId = false;
            textcphdqmfhzId = false;

            this.Id = string.Empty;
            record = new NursingFormRecord();
            dateEditriqi.DateTime = DateTime.Now;
            textsudu.EditValue = "    /";
            textSuDu5.EditValue = "    /";
            textBuLiangFanYing.EditValue = "    /";
            textBuLiangFanYing1.EditValue = "    /";
        }
        /// <summary>
        /// 清除控件值
        /// </summary>
        /// <param name="c"></param>
        private static void ControlValueClear(Control c)
        {
            if (c is DateEdit)
                ((DateEdit)c).Text = string.Empty;
            if (c is TextEdit)
                ((TextEdit)c).Text = string.Empty;
            if (c is CheckEdit)
                ((CheckEdit)c).Checked = false;
            if (c is RadioGroup)
                ((RadioGroup)c).SelectedIndex = -1;
            if (c is ComboBoxEdit)
                ((ComboBoxEdit)c).SelectedIndex = -1;
        }

        private void comboBoxEditshenzhi_KeyPress(object sender, KeyPressEventArgs e)
        {
            Regex regex = new Regex("[ \\[\\]\\^\\-_*×――(^)$%~!@#$…&%￥—+=<>《》!！??？:：•`·、。，；,.;\"‘’“”\\{\\}\\|'\\\\/【】]");
            if (regex.IsMatch(e.KeyChar.ToString()))
            {
                e.Handled = true;
                return;
            }
        }

        #region 文本框双击时间获取签名
        //输血前核对签名--初核者
        bool textsxqhdqmchzId = false;
        private void textsxqhdqmchz_DoubleClick(object sender, EventArgs e)
        {
            this.textsxqhdqmchz.Text = this.LoginUser.UserName;
            textsxqhdqmchzId = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textsxqhdqmchz, picElectronicSignature1, textsxqhdqmchz.Location);
        }
        //输血前核对签名--复核者
        bool textsxqhdqmfhzId = false;
        private void textsxqhdqmfhz_DoubleClick(object sender, EventArgs e)
        {
            this.textsxqhdqmfhz.Text = this.LoginUser.UserName;
            textsxqhdqmfhzId = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textsxqhdqmfhz, picElectronicSignature2, textsxqhdqmfhz.Location);
        }
        //床旁核对签名--初核者
        bool textcphdqmchzId = false;
        private void textcphdqmchz_DoubleClick(object sender, EventArgs e)
        {
            this.textcphdqmchz.Text = this.LoginUser.UserName;
            textcphdqmchzId = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textcphdqmchz, picElectronicSignature3, textcphdqmchz.Location);
        }
        //床旁核对签名--复核者
        bool textcphdqmfhzId = false;
        private void textcphdqmfhz_DoubleClick(object sender, EventArgs e)
        {
            this.textcphdqmfhz.Text = this.LoginUser.UserName;
            textcphdqmfhzId = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textcphdqmfhz, picElectronicSignature4, textcphdqmfhz.Location);
        }
        #endregion

        #region 按钮获取签名
        //输血前核对签名--初核者
        private void shuxueqian_chuhezhe_qianming_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textsxqhdqmchz.Text)) return;
            this.textsxqhdqmchz.Text = this.LoginUser.UserName;
            textsxqhdqmchzId = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textsxqhdqmchz, picElectronicSignature1, textsxqhdqmchz.Location);
        }
        //输血前核对签名--复核者
        private void shuxueqian_fuhezhe_qianming_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textsxqhdqmfhz.Text)) return;
            this.textsxqhdqmfhz.Text = this.LoginUser.UserName;
            textsxqhdqmfhzId = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textsxqhdqmfhz, picElectronicSignature2, textsxqhdqmfhz.Location);
        }
        //床旁核对签名--初核者
        private void chuangpanghedui_chuhezhe_qianming_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textcphdqmchz.Text)) return;
            this.textcphdqmchz.Text = this.LoginUser.UserName;
            textcphdqmchzId = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textcphdqmchz, picElectronicSignature3, textcphdqmchz.Location);

        }
        //床旁核对签名--复核者
        private void chuangpanghedui_fuhezhe_qianming_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textcphdqmfhz.Text)) return;
            this.textcphdqmfhz.Text = this.LoginUser.UserName;
            textcphdqmfhzId = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textcphdqmfhz, picElectronicSignature4, textcphdqmfhz.Location);
        }
        #endregion


    }
}